const Koa = require('koa')


// 实例化应用
const app = new Koa()

async function logger(ctx, next) {
    const start = Date.now()
    await next() // 将控制权交给下一个中间件
    console.log(`${ctx.method} ${ctx.path}  ${Date.now() - start}ms`);

}


app.use(logger)

app.use(async (ctx) => {
    console.log('router');
    ctx.body = 'Hello world'
})

app.listen(8899, () => {
    console.log('listen on 8899');
})